#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <regex>
 
using namespace std;
 
vector<int> split(string input_str, string chars) {
    vector<int> results;
    regex rgx(chars);
    sregex_token_iterator iter(input_str.begin(), input_str.end(), rgx, -1);
    sregex_token_iterator end;
    while (iter != end) {
        results.push_back(stoi(*iter));
        ++iter;
    }
    return results;
}
 
int main() {
    string input_str;
    getline(cin, input_str);
    vector<int> nums = split(input_str, " ");
    int x = nums[0];
    int y = nums[1];
    int count_x = nums[2];
    int count_y = nums[3];
 
    int left = 1;
    int right = INT_MAX;
    while (true) {
        if (left >= right) {
            break;
        } else {
            int mid = (left + right) >> 1;
            int target = max(0, count_x - mid / y + mid / (x * y)) + max(0, count_y - mid / x + mid / (x * y));
            if (mid - mid / x - mid / y + mid / (x * y) >= target) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
    }
    cout << left << endl;
 
    return 0;
}